﻿using OBUCare.Core.DataAccess;
using OBUCare.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OBUCare.Web.Areas.Admin.Controllers
{
    public class OneRepairController : Controller
    {
        private OBU_CAREContext db = new OBU_CAREContext();

        //
        // GET: /Admin/DictType/

        public ActionResult Index()
        {
            return RedirectToAction("List");
        }
        public ViewResult List()
        {
            var allItems = db.SPECIAL_REPAIR_FEE.ToList();
            var listItems = from i in allItems
                            orderby i.START_DATE descending
                            select i;
            return View(listItems.ToList());
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Insert()
        {
            var m = new SPECIAL_REPAIR_FEE();

            if (ModelState.IsValid && TryUpdateModel(m))
            {
                m.CREATED_TIME = DateTime.Now;
                db.SPECIAL_REPAIR_FEE.Add(m);
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Update(int id)
        {
            var m = db.SPECIAL_REPAIR_FEE.Find(id);

            if (m == null)
            {
                return RedirectToAction("Index");
            }
            if (TryUpdateModel(m))
            {
                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }

        //
        // POST: /Admin/CodeTable/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var m = db.SPECIAL_REPAIR_FEE.Find(id);
            db.SPECIAL_REPAIR_FEE.Remove(m);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    }
}
